/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.institution.controller;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.institution.bean.LawCategory;
import com.koron.institution.service.api.LawCategoryService;
import com.koron.institution.uitls.BusinessCode;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "lawCategory", description = "法规库目录Api类")
@RestController
@RequestMapping(value = "/lawCategory")
public class LawCategoryController {

    @Autowired
    private LawCategoryService lawCategoryService;

    @ApiOperation("法规目录列表")
    @RequestMapping(value = "/categoryList.htm", method = {RequestMethod.GET})
    public MessageBean<?> categoryList() {
        return lawCategoryService.getCategoryList();
    }


    @ApiOperation("新增法规目录")
    @RequestMapping(value = "/categoryAdd.htm", method = {RequestMethod.POST})
    @Log(title = "新增法规目录", businessModule = "法规库", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<?> categoryAdd(@RequestBody LawCategory lawCategory, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user) {
        if (null==user){
            MessageBean<?> msg=new MessageBean<>();
            msg.setCode(BusinessCode.NOT_LONGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LONGIN.getDescription());
            return msg;
        }
        return lawCategoryService.addCategory(lawCategory, user);
    }

    @ApiOperation("删除法规目录")
    @RequestMapping(value = "/categoryDelete.htm", method = {RequestMethod.POST})
    @ApiImplicitParam(name = "categoryId", value = "目录id", required = true, paramType = "query", dataType = "String")
    @Log(title = "删除法规目录", businessModule = "法规库", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<?> categoryDelete(String categoryId, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user) {
        if (null==user){
            MessageBean<?> msg=new MessageBean<>();
            msg.setCode(BusinessCode.NOT_LONGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LONGIN.getDescription());
            return msg;
        }
        return lawCategoryService.deleteCategory(categoryId, user);
    }

    @ApiOperation("修改法规目录")
    @RequestMapping(value = "/categoryUpdate.htm", method = {RequestMethod.POST})
    @ApiImplicitParam(name = "categoryId", value = "目录id", required = true, paramType = "query", dataType = "String")
    @Log(title = "修改法规目录", businessModule = "法规库", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> categoryUpdate(@RequestBody LawCategory category, @SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user) {
        if (null==user){
            MessageBean<?> msg=new MessageBean<>();
            msg.setCode(BusinessCode.NOT_LONGIN.getCode());
            msg.setDescription(BusinessCode.NOT_LONGIN.getDescription());
            return msg;
        }
        return lawCategoryService.updateCategory(category, user);
    }

}
